# -*- coding: utf-8 -*-
# created by Src - 一路好时光

#应用场景
#时间的记录显示
#时间的转换：格式
#时间的运算：差值
#1970-01-01日世界上第一个unix系统诞生，为了纪念

import time
print(time.time())#1720923275.5871987
start = time.time()
# time.sleep(3)#睡眠3秒钟
end = time.time()
print(end - start)#3.0017130374908447

#返回时间对象
#time.struct_time(tm_year=2024, tm_mon=7, tm_mday=14, tm_hour=10, tm_min=15, tm_sec=55, tm_wday=6, tm_yday=196, tm_isdst=0)
print(time.localtime())
#time.struct_time(tm_year=2012, tm_mon=4, tm_mday=15, tm_hour=7, tm_min=0, tm_sec=44, tm_wday=6, tm_yday=106, tm_isdst=0)
print(time.localtime(1334444444))
#UTC时间，与北京时间相差8小时
#time.struct_time(tm_year=2024, tm_mon=7, tm_mday=14, tm_hour=2, tm_min=19, tm_sec=38, tm_wday=6, tm_yday=196, tm_isdst=0)
print(time.gmtime())
#将时间对象上冻你换为时间戳  1720923685.0
print(time.mktime(time.localtime()))
#时间转字符串2024-07-14 10:22:07
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))

time_str = time.strftime('%Y-%m-%d %H:%M:%S')#2024-07-14 10:27:09
print(time_str)

#time.struct_time(tm_year=2024, tm_mon=7, tm_mday=14, tm_hour=10, tm_min=28, tm_sec=57, tm_wday=6, tm_yday=196, tm_isdst=-1)
print(time.strptime(time_str, '%Y-%m-%d %H:%M:%S'))

